package com.nuoniu.sibanyun.mapper.production;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.annotation.DataAuth;
import com.nuoniu.sibanyun.entity.dto.VProductionWorkDetailSearchDto;
import com.nuoniu.sibanyun.entity.dto.mobile.DispatchSearchDto;
import com.nuoniu.sibanyun.entity.dto.mobile.ProcedureDetailSearchDto;
import com.nuoniu.sibanyun.entity.production.VProductionWorkProcedureDetail;
import com.nuoniu.sibanyun.entity.vo.*;
import com.nuoniu.sibanyun.entity.vo.reportVo.UnFinishProductionWorkDetailSimpleVo;
import com.nuoniu.sibanyun.entity.vo.reportVo.UnFinishProductionWorkProcedureVo;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 生产加工单——工序明细 Mapper 接口
 * </p>
 *
 * @author 白强
 * @since 2021-03-20
 */
public interface VProductionWorkProcedureDetailMapper extends BaseMapper<VProductionWorkProcedureDetail> {

    VProductionWorkProcedureDetailVo getVProductionWorkProcedureDetailVo(Integer companyId,Integer accountId, Integer id);

    VProductionWorkProcedureDetailVo getVProductionWorkProcedureDetailVoByProcedureId(Integer companyId,Integer accountId,Integer detailId,Integer procedureId);


    VProductionWorkProcedureDetailVo getVProductionWorkProcedureDetailVoByOrder(Integer companyId,Integer accountId,Integer detailId, Integer order);

    BigDecimal getTotalCumUnqualifiedQuantityBeginOrder(Integer companyId,Integer accountId,Integer detailId, Integer order);

    BigDecimal getLastProcedureCumQualifiedQuantityBeginOrder(Integer companyId,Integer accountId,Integer productionDispatchId, Integer order);

    /**
     * 查询 上道工序 是否完工
     * @param companyId
     * @param accountId
     * @param productionDispatchId  派工单ID
     * @param order
     * @return
     */
    boolean isLastProcedureFinished(Integer companyId,Integer accountId,Integer productionDispatchId, Integer order);


    /**
     * 查询 工序明细
     * @param companyId
     * @param accountId
     * @param dispatchId
     * @return
     */
    List<VProductionWorkProcedureDetailVo> listByProductionDispatchId(Integer companyId,Integer accountId,Long dispatchId);
    /**
     * 查询 工序明细
     * @param companyId
     * @param accountId
     * @param productionWorkMainId
     * @return
     */
    List<VProductionWorkProcedureDetailVo> listByProductionWorkId(Integer companyId,Integer accountId,Long productionWorkMainId);


    /**
     * 根据数据权限 获取未完工的 派工单(废弃)
     * @param companyId
     * @param accountId
     * @param productionDispatchMainSearchDto
     * @return
     */
    @DataAuth(tableAlias = "dm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<VProductionDispatchSimpleVo> listUnFinishProductionDispatchSimpleVo(Integer companyId, Integer accountId,  @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);
    /**
     * 根据数据权限 获取未完工 的派工任务（废弃）
     * @param companyId
     * @param accountId
     * @return
     */
    @DataAuth(tableAlias = "dm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<VProcedureDetailSimpleVo> listUnFinishProcedureDetailSimpleVo(Integer companyId, Integer accountId,  @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);


    /**
     * 根据数据权限 获取未完工的 加工单明细
     * @param companyId
     * @param accountId
     * @param productionDispatchMainSearchDto
     * @return
     */
    @DataAuth(tableAlias = "pwm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<UnFinishProductionWorkDetailSimpleVo> listUnFinishProductionWorkDetailSimpleVo(Integer companyId, Integer accountId, @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);

    /**
     * 根据数据权限 获取未完工的 产品工序明细
     * @param companyId
     * @param accountId
     * @param productionDispatchMainSearchDto
     * @return
     */
    @DataAuth(tableAlias = "pwm",personalField = "create_user_id",companyField = "company_id",officeField = "office_id")
    List<UnFinishProductionWorkProcedureVo> listUnFinishProductionWorkProcedureVo(Integer companyId, Integer accountId, @Param("dto") VProductionWorkDetailSearchDto productionDispatchMainSearchDto);

    /**
     * 获取未完成的派工单（移动端）
     * @param dispatchSearchDto
     * @return
     */
    Page<VProductionDispatchSimpleVo> pagePersonalDispatch(Page page, Integer companyId, Integer accountId, String officeIds, String userIds, @Param("dto")DispatchSearchDto dispatchSearchDto);

    /**
     * 移动端 获取自己没有完成的工序任务卡
     * @param companyId
     * @param accountId
     * @param officeIds
     * @param userIds
     * @param procedureDetailSearchDto
     * @return
     */
    Page<VProcedureDetailSimpleVo> pageVProcedureDetailSimpleVo(Page page, Integer companyId, Integer accountId, String officeIds, String userIds, @Param("dto") ProcedureDetailSearchDto procedureDetailSearchDto);

    /**
     * @title 校验 是否 汇报
     * @description 
     * @author 白强 
     * @updateTime 2021/12/25 16:04 
     * @throws 
     */
    boolean checkWorkReport( Integer companyId, Integer accountId, Long mainId);


}
